{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Task \n",
    "\n",
    "This notebook prepares HRS data. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd \n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_stata('../data_sources/hrs/rndhrs_n.dta',convert_categoricals=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [],
   "source": [
    "vars = ['rahhidpn','r7iwstat','r8iwstat','r7agey_b','r8agey_b','r7adla','r8adla','r7wtresp','r8wtresp','h7itot','h8itot','r7bmi','r8bmi','r7drink','r8drink','r7smokev','r8smokev','r7drinkd','r8drinkd','r7drinkn','r8drinkn','r7vgactx','r8vgactx','r7mdactx','r8mdactx','r7shlt','r8shlt','r7hibpe','r8hibpe','r7diabe','r8diabe','r7cancre','r8cancre','r7lunge','r8lunge','r7hearte','r8hearte','r7stroke','r8stroke']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>r7iwstat</th>\n",
       "      <th>r8iwstat</th>\n",
       "      <th>r7agey_b</th>\n",
       "      <th>r8agey_b</th>\n",
       "      <th>r7adla</th>\n",
       "      <th>r8adla</th>\n",
       "      <th>r7wtresp</th>\n",
       "      <th>r8wtresp</th>\n",
       "      <th>h7itot</th>\n",
       "      <th>h8itot</th>\n",
       "      <th>...</th>\n",
       "      <th>r7diabe</th>\n",
       "      <th>r8diabe</th>\n",
       "      <th>r7cancre</th>\n",
       "      <th>r8cancre</th>\n",
       "      <th>r7lunge</th>\n",
       "      <th>r8lunge</th>\n",
       "      <th>r7hearte</th>\n",
       "      <th>r8hearte</th>\n",
       "      <th>r7stroke</th>\n",
       "      <th>r8stroke</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>17823.0</td>\n",
       "      <td>17823.0</td>\n",
       "      <td>17823.000000</td>\n",
       "      <td>17823.000000</td>\n",
       "      <td>17819.00000</td>\n",
       "      <td>17814.000000</td>\n",
       "      <td>17823.000000</td>\n",
       "      <td>17823.000000</td>\n",
       "      <td>1.782300e+04</td>\n",
       "      <td>1.782300e+04</td>\n",
       "      <td>...</td>\n",
       "      <td>17802.000000</td>\n",
       "      <td>17789.000000</td>\n",
       "      <td>17790.000000</td>\n",
       "      <td>17779.000000</td>\n",
       "      <td>17805.000000</td>\n",
       "      <td>17790.000000</td>\n",
       "      <td>17800.000000</td>\n",
       "      <td>17789.000000</td>\n",
       "      <td>17812.000000</td>\n",
       "      <td>17799.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>66.026034</td>\n",
       "      <td>68.020591</td>\n",
       "      <td>0.28739</td>\n",
       "      <td>0.391209</td>\n",
       "      <td>4057.646580</td>\n",
       "      <td>4181.051058</td>\n",
       "      <td>6.163010e+04</td>\n",
       "      <td>6.552219e+04</td>\n",
       "      <td>...</td>\n",
       "      <td>0.166498</td>\n",
       "      <td>0.193940</td>\n",
       "      <td>0.120461</td>\n",
       "      <td>0.142471</td>\n",
       "      <td>0.075878</td>\n",
       "      <td>0.091849</td>\n",
       "      <td>0.211124</td>\n",
       "      <td>0.245657</td>\n",
       "      <td>0.071413</td>\n",
       "      <td>0.088320</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>11.041708</td>\n",
       "      <td>11.048250</td>\n",
       "      <td>0.84986</td>\n",
       "      <td>1.012765</td>\n",
       "      <td>2824.529223</td>\n",
       "      <td>3023.181123</td>\n",
       "      <td>1.014819e+05</td>\n",
       "      <td>3.229373e+05</td>\n",
       "      <td>...</td>\n",
       "      <td>0.372538</td>\n",
       "      <td>0.395394</td>\n",
       "      <td>0.325509</td>\n",
       "      <td>0.349543</td>\n",
       "      <td>0.264810</td>\n",
       "      <td>0.288821</td>\n",
       "      <td>0.408117</td>\n",
       "      <td>0.430488</td>\n",
       "      <td>0.257520</td>\n",
       "      <td>0.283767</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>24.000000</td>\n",
       "      <td>26.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>57.000000</td>\n",
       "      <td>59.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2139.000000</td>\n",
       "      <td>2125.000000</td>\n",
       "      <td>1.860000e+04</td>\n",
       "      <td>1.879600e+04</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>66.000000</td>\n",
       "      <td>68.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>3480.000000</td>\n",
       "      <td>3534.000000</td>\n",
       "      <td>3.713600e+04</td>\n",
       "      <td>3.701639e+04</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>74.000000</td>\n",
       "      <td>76.000000</td>\n",
       "      <td>0.00000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>5142.000000</td>\n",
       "      <td>5256.000000</td>\n",
       "      <td>7.132500e+04</td>\n",
       "      <td>7.023280e+04</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>102.000000</td>\n",
       "      <td>104.000000</td>\n",
       "      <td>5.00000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>16170.000000</td>\n",
       "      <td>17035.000000</td>\n",
       "      <td>3.530526e+06</td>\n",
       "      <td>2.536019e+07</td>\n",
       "      <td>...</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8 rows × 38 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       r7iwstat  r8iwstat      r7agey_b      r8agey_b       r7adla  \\\n",
       "count   17823.0   17823.0  17823.000000  17823.000000  17819.00000   \n",
       "mean        1.0       1.0     66.026034     68.020591      0.28739   \n",
       "std         0.0       0.0     11.041708     11.048250      0.84986   \n",
       "min         1.0       1.0     24.000000     26.000000      0.00000   \n",
       "25%         1.0       1.0     57.000000     59.000000      0.00000   \n",
       "50%         1.0       1.0     66.000000     68.000000      0.00000   \n",
       "75%         1.0       1.0     74.000000     76.000000      0.00000   \n",
       "max         1.0       1.0    102.000000    104.000000      5.00000   \n",
       "\n",
       "             r8adla      r7wtresp      r8wtresp        h7itot        h8itot  \\\n",
       "count  17814.000000  17823.000000  17823.000000  1.782300e+04  1.782300e+04   \n",
       "mean       0.391209   4057.646580   4181.051058  6.163010e+04  6.552219e+04   \n",
       "std        1.012765   2824.529223   3023.181123  1.014819e+05  3.229373e+05   \n",
       "min        0.000000      0.000000      0.000000  0.000000e+00  0.000000e+00   \n",
       "25%        0.000000   2139.000000   2125.000000  1.860000e+04  1.879600e+04   \n",
       "50%        0.000000   3480.000000   3534.000000  3.713600e+04  3.701639e+04   \n",
       "75%        0.000000   5142.000000   5256.000000  7.132500e+04  7.023280e+04   \n",
       "max        5.000000  16170.000000  17035.000000  3.530526e+06  2.536019e+07   \n",
       "\n",
       "       ...       r7diabe       r8diabe      r7cancre      r8cancre  \\\n",
       "count  ...  17802.000000  17789.000000  17790.000000  17779.000000   \n",
       "mean   ...      0.166498      0.193940      0.120461      0.142471   \n",
       "std    ...      0.372538      0.395394      0.325509      0.349543   \n",
       "min    ...      0.000000      0.000000      0.000000      0.000000   \n",
       "25%    ...      0.000000      0.000000      0.000000      0.000000   \n",
       "50%    ...      0.000000      0.000000      0.000000      0.000000   \n",
       "75%    ...      0.000000      0.000000      0.000000      0.000000   \n",
       "max    ...      1.000000      1.000000      1.000000      1.000000   \n",
       "\n",
       "            r7lunge       r8lunge      r7hearte      r8hearte      r7stroke  \\\n",
       "count  17805.000000  17790.000000  17800.000000  17789.000000  17812.000000   \n",
       "mean       0.075878      0.091849      0.211124      0.245657      0.071413   \n",
       "std        0.264810      0.288821      0.408117      0.430488      0.257520   \n",
       "min        0.000000      0.000000      0.000000      0.000000      0.000000   \n",
       "25%        0.000000      0.000000      0.000000      0.000000      0.000000   \n",
       "50%        0.000000      0.000000      0.000000      0.000000      0.000000   \n",
       "75%        0.000000      0.000000      0.000000      0.000000      0.000000   \n",
       "max        1.000000      1.000000      1.000000      1.000000      1.000000   \n",
       "\n",
       "           r8stroke  \n",
       "count  17799.000000  \n",
       "mean       0.088320  \n",
       "std        0.283767  \n",
       "min        0.000000  \n",
       "25%        0.000000  \n",
       "50%        0.000000  \n",
       "75%        0.000000  \n",
       "max        1.000000  \n",
       "\n",
       "[8 rows x 38 columns]"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hrs = df.loc[(df.r7iwstat==1) & (df.r8iwstat==1),vars]\n",
    "hrs.describe()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "CPI adjustment to bring to 2004 dollars. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [],
   "source": [
    "hrs.h8itot = hrs.h8itot * 189.3/200.47"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "vars = ['rahhidpn','r7iwstat','r8iwstat','r7agey_b','r8agey_b','r7adla','r8adla','r7wtresp','r8wtresp','h7itot','h8itot','r7bmi','r8bmi','r7drink','r8drink','r7smokev','r8smokev','r7drinkd','r8drinkd','r7drinkn','r8drinkn','r7vgactx','r8vgactx','r7mdactx','r8mdactx','r7shlt','r8shlt','r7hibpe','r8hibpe','r7diabe','r8diabe','r7cancre','r8cancre','r7lunge','r8lunge','r7hearte','r8hearte','r7stroke','r8stroke']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Bunch of renames to append wave 1 and 2 rather than 7 and 8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "for c in hrs.columns:\n",
    "\tif 'r7' in c:\n",
    "\t\thrs = hrs.rename({c:'r'+c[2:]+'_w1'},axis=1)\n",
    "\tif 'r8' in c:\n",
    "\t\thrs = hrs.rename({c:'r'+c[2:]+'_w2'},axis=1)\n",
    "\tif 'h7' in c:\n",
    "\t\thrs = hrs.rename({c:'h'+c[2:]+'_w1'},axis=1)\n",
    "\tif 'h8' in c:\n",
    "\t\thrs = hrs.rename({c:'h'+c[2:]+'_w2'},axis=1)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Other renames"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "hrs = hrs.rename({'ragey_b_w1':'rage_w1','ragey_b_w2':'rage_w2'},axis=1)\n",
    "hrs = hrs.rename({'rwtresp_w1':'wgid_w1','rwtresp_w2':'wgid_w2'},axis=1)\n",
    "hrs = hrs.rename({'rahhidpn':'hhidpn'},axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In SHARE, income for 2nd wave is net of taxes. HRS asks about gross income. We use the Gouveia and Strauss estimates of the averate tax function for the U.S. to compute after-tax income. See Fonseca et al. (2020,JEEA) for details on this function. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "pars = [0.264,0.964,0.014027]\n",
    "def gsfunc(row,var):\n",
    "    inck = row[var]*0.001\n",
    "    atr = pars[0]- pars[0]*(pars[2]*(inck**(pars[1])) + 1.0 )**(-1.0/pars[1])\n",
    "    return row[var]*(1-atr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [],
   "source": [
    "hrs['hitot_w2'] = hrs.apply(gsfunc,var='hitot_w2',axis=1)\n",
    "hrs['hitot_w1'] = hrs.apply(gsfunc,var='hitot_w1',axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>count</th>\n",
       "      <th>mean</th>\n",
       "      <th>std</th>\n",
       "      <th>min</th>\n",
       "      <th>25%</th>\n",
       "      <th>50%</th>\n",
       "      <th>75%</th>\n",
       "      <th>max</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>riwstat_w1</th>\n",
       "      <td>17823.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>riwstat_w2</th>\n",
       "      <td>17823.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rage_w1</th>\n",
       "      <td>17823.0</td>\n",
       "      <td>66.026034</td>\n",
       "      <td>11.041708</td>\n",
       "      <td>24.0</td>\n",
       "      <td>57.000000</td>\n",
       "      <td>66.000000</td>\n",
       "      <td>74.000000</td>\n",
       "      <td>1.020000e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rage_w2</th>\n",
       "      <td>17823.0</td>\n",
       "      <td>68.020591</td>\n",
       "      <td>11.048250</td>\n",
       "      <td>26.0</td>\n",
       "      <td>59.000000</td>\n",
       "      <td>68.000000</td>\n",
       "      <td>76.000000</td>\n",
       "      <td>1.040000e+02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>radla_w1</th>\n",
       "      <td>17819.0</td>\n",
       "      <td>0.287390</td>\n",
       "      <td>0.849860</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>5.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>radla_w2</th>\n",
       "      <td>17814.0</td>\n",
       "      <td>0.391209</td>\n",
       "      <td>1.012765</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>5.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>wgid_w1</th>\n",
       "      <td>17823.0</td>\n",
       "      <td>4057.646580</td>\n",
       "      <td>2824.529223</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2139.000000</td>\n",
       "      <td>3480.000000</td>\n",
       "      <td>5142.000000</td>\n",
       "      <td>1.617000e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>wgid_w2</th>\n",
       "      <td>17823.0</td>\n",
       "      <td>4181.051058</td>\n",
       "      <td>3023.181123</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2125.000000</td>\n",
       "      <td>3534.000000</td>\n",
       "      <td>5256.000000</td>\n",
       "      <td>1.703500e+04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>hitot_w1</th>\n",
       "      <td>17823.0</td>\n",
       "      <td>52561.892991</td>\n",
       "      <td>77555.089756</td>\n",
       "      <td>0.0</td>\n",
       "      <td>17634.939712</td>\n",
       "      <td>33965.362444</td>\n",
       "      <td>62397.849517</td>\n",
       "      <td>2.619935e+06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>hitot_w2</th>\n",
       "      <td>17823.0</td>\n",
       "      <td>52507.115075</td>\n",
       "      <td>225533.864531</td>\n",
       "      <td>0.0</td>\n",
       "      <td>16860.893545</td>\n",
       "      <td>32086.924471</td>\n",
       "      <td>58327.461455</td>\n",
       "      <td>1.764707e+07</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rbmi_w1</th>\n",
       "      <td>17518.0</td>\n",
       "      <td>27.634544</td>\n",
       "      <td>5.652297</td>\n",
       "      <td>9.6</td>\n",
       "      <td>23.799999</td>\n",
       "      <td>26.600000</td>\n",
       "      <td>30.500000</td>\n",
       "      <td>7.130000e+01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rbmi_w2</th>\n",
       "      <td>17551.0</td>\n",
       "      <td>27.870140</td>\n",
       "      <td>5.864652</td>\n",
       "      <td>10.6</td>\n",
       "      <td>23.900000</td>\n",
       "      <td>27.100000</td>\n",
       "      <td>30.900000</td>\n",
       "      <td>8.270000e+01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rdrink_w1</th>\n",
       "      <td>17821.0</td>\n",
       "      <td>0.497784</td>\n",
       "      <td>0.500009</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rdrink_w2</th>\n",
       "      <td>17818.0</td>\n",
       "      <td>0.496408</td>\n",
       "      <td>0.500001</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rsmokev_w1</th>\n",
       "      <td>17717.0</td>\n",
       "      <td>0.569453</td>\n",
       "      <td>0.495167</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rsmokev_w2</th>\n",
       "      <td>17717.0</td>\n",
       "      <td>0.569453</td>\n",
       "      <td>0.495167</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rdrinkd_w1</th>\n",
       "      <td>17791.0</td>\n",
       "      <td>1.107358</td>\n",
       "      <td>2.057451</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>7.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rdrinkd_w2</th>\n",
       "      <td>17794.0</td>\n",
       "      <td>1.092615</td>\n",
       "      <td>2.062958</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>7.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rdrinkn_w1</th>\n",
       "      <td>17784.0</td>\n",
       "      <td>0.704510</td>\n",
       "      <td>1.485732</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>5.000000e+01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rdrinkn_w2</th>\n",
       "      <td>17780.0</td>\n",
       "      <td>0.648763</td>\n",
       "      <td>1.344182</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>4.500000e+01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rvgactx_w1</th>\n",
       "      <td>17808.0</td>\n",
       "      <td>4.029818</td>\n",
       "      <td>1.316085</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>5.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rvgactx_w2</th>\n",
       "      <td>17801.0</td>\n",
       "      <td>4.079041</td>\n",
       "      <td>1.318916</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>5.000000</td>\n",
       "      <td>5.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rmdactx_w1</th>\n",
       "      <td>17813.0</td>\n",
       "      <td>2.924213</td>\n",
       "      <td>1.272445</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>5.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rmdactx_w2</th>\n",
       "      <td>17809.0</td>\n",
       "      <td>2.923971</td>\n",
       "      <td>1.369287</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>5.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rshlt_w1</th>\n",
       "      <td>17812.0</td>\n",
       "      <td>2.826690</td>\n",
       "      <td>1.118743</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>5.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rshlt_w2</th>\n",
       "      <td>17798.0</td>\n",
       "      <td>2.881897</td>\n",
       "      <td>1.129472</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>3.000000</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>5.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rhibpe_w1</th>\n",
       "      <td>17802.0</td>\n",
       "      <td>0.504157</td>\n",
       "      <td>0.499997</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rhibpe_w2</th>\n",
       "      <td>17796.0</td>\n",
       "      <td>0.554900</td>\n",
       "      <td>0.496991</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rdiabe_w1</th>\n",
       "      <td>17802.0</td>\n",
       "      <td>0.166498</td>\n",
       "      <td>0.372538</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rdiabe_w2</th>\n",
       "      <td>17789.0</td>\n",
       "      <td>0.193940</td>\n",
       "      <td>0.395394</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rcancre_w1</th>\n",
       "      <td>17790.0</td>\n",
       "      <td>0.120461</td>\n",
       "      <td>0.325509</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rcancre_w2</th>\n",
       "      <td>17779.0</td>\n",
       "      <td>0.142471</td>\n",
       "      <td>0.349543</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rlunge_w1</th>\n",
       "      <td>17805.0</td>\n",
       "      <td>0.075878</td>\n",
       "      <td>0.264810</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rlunge_w2</th>\n",
       "      <td>17790.0</td>\n",
       "      <td>0.091849</td>\n",
       "      <td>0.288821</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rhearte_w1</th>\n",
       "      <td>17800.0</td>\n",
       "      <td>0.211124</td>\n",
       "      <td>0.408117</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rhearte_w2</th>\n",
       "      <td>17789.0</td>\n",
       "      <td>0.245657</td>\n",
       "      <td>0.430488</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rstroke_w1</th>\n",
       "      <td>17812.0</td>\n",
       "      <td>0.071413</td>\n",
       "      <td>0.257520</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>rstroke_w2</th>\n",
       "      <td>17799.0</td>\n",
       "      <td>0.088320</td>\n",
       "      <td>0.283767</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000e+00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              count          mean            std   min           25%  \\\n",
       "riwstat_w1  17823.0      1.000000       0.000000   1.0      1.000000   \n",
       "riwstat_w2  17823.0      1.000000       0.000000   1.0      1.000000   \n",
       "rage_w1     17823.0     66.026034      11.041708  24.0     57.000000   \n",
       "rage_w2     17823.0     68.020591      11.048250  26.0     59.000000   \n",
       "radla_w1    17819.0      0.287390       0.849860   0.0      0.000000   \n",
       "radla_w2    17814.0      0.391209       1.012765   0.0      0.000000   \n",
       "wgid_w1     17823.0   4057.646580    2824.529223   0.0   2139.000000   \n",
       "wgid_w2     17823.0   4181.051058    3023.181123   0.0   2125.000000   \n",
       "hitot_w1    17823.0  52561.892991   77555.089756   0.0  17634.939712   \n",
       "hitot_w2    17823.0  52507.115075  225533.864531   0.0  16860.893545   \n",
       "rbmi_w1     17518.0     27.634544       5.652297   9.6     23.799999   \n",
       "rbmi_w2     17551.0     27.870140       5.864652  10.6     23.900000   \n",
       "rdrink_w1   17821.0      0.497784       0.500009   0.0      0.000000   \n",
       "rdrink_w2   17818.0      0.496408       0.500001   0.0      0.000000   \n",
       "rsmokev_w1  17717.0      0.569453       0.495167   0.0      0.000000   \n",
       "rsmokev_w2  17717.0      0.569453       0.495167   0.0      0.000000   \n",
       "rdrinkd_w1  17791.0      1.107358       2.057451   0.0      0.000000   \n",
       "rdrinkd_w2  17794.0      1.092615       2.062958   0.0      0.000000   \n",
       "rdrinkn_w1  17784.0      0.704510       1.485732   0.0      0.000000   \n",
       "rdrinkn_w2  17780.0      0.648763       1.344182   0.0      0.000000   \n",
       "rvgactx_w1  17808.0      4.029818       1.316085   1.0      3.000000   \n",
       "rvgactx_w2  17801.0      4.079041       1.318916   1.0      3.000000   \n",
       "rmdactx_w1  17813.0      2.924213       1.272445   1.0      2.000000   \n",
       "rmdactx_w2  17809.0      2.923971       1.369287   1.0      2.000000   \n",
       "rshlt_w1    17812.0      2.826690       1.118743   1.0      2.000000   \n",
       "rshlt_w2    17798.0      2.881897       1.129472   1.0      2.000000   \n",
       "rhibpe_w1   17802.0      0.504157       0.499997   0.0      0.000000   \n",
       "rhibpe_w2   17796.0      0.554900       0.496991   0.0      0.000000   \n",
       "rdiabe_w1   17802.0      0.166498       0.372538   0.0      0.000000   \n",
       "rdiabe_w2   17789.0      0.193940       0.395394   0.0      0.000000   \n",
       "rcancre_w1  17790.0      0.120461       0.325509   0.0      0.000000   \n",
       "rcancre_w2  17779.0      0.142471       0.349543   0.0      0.000000   \n",
       "rlunge_w1   17805.0      0.075878       0.264810   0.0      0.000000   \n",
       "rlunge_w2   17790.0      0.091849       0.288821   0.0      0.000000   \n",
       "rhearte_w1  17800.0      0.211124       0.408117   0.0      0.000000   \n",
       "rhearte_w2  17789.0      0.245657       0.430488   0.0      0.000000   \n",
       "rstroke_w1  17812.0      0.071413       0.257520   0.0      0.000000   \n",
       "rstroke_w2  17799.0      0.088320       0.283767   0.0      0.000000   \n",
       "\n",
       "                     50%           75%           max  \n",
       "riwstat_w1      1.000000      1.000000  1.000000e+00  \n",
       "riwstat_w2      1.000000      1.000000  1.000000e+00  \n",
       "rage_w1        66.000000     74.000000  1.020000e+02  \n",
       "rage_w2        68.000000     76.000000  1.040000e+02  \n",
       "radla_w1        0.000000      0.000000  5.000000e+00  \n",
       "radla_w2        0.000000      0.000000  5.000000e+00  \n",
       "wgid_w1      3480.000000   5142.000000  1.617000e+04  \n",
       "wgid_w2      3534.000000   5256.000000  1.703500e+04  \n",
       "hitot_w1    33965.362444  62397.849517  2.619935e+06  \n",
       "hitot_w2    32086.924471  58327.461455  1.764707e+07  \n",
       "rbmi_w1        26.600000     30.500000  7.130000e+01  \n",
       "rbmi_w2        27.100000     30.900000  8.270000e+01  \n",
       "rdrink_w1       0.000000      1.000000  1.000000e+00  \n",
       "rdrink_w2       0.000000      1.000000  1.000000e+00  \n",
       "rsmokev_w1      1.000000      1.000000  1.000000e+00  \n",
       "rsmokev_w2      1.000000      1.000000  1.000000e+00  \n",
       "rdrinkd_w1      0.000000      1.000000  7.000000e+00  \n",
       "rdrinkd_w2      0.000000      1.000000  7.000000e+00  \n",
       "rdrinkn_w1      0.000000      1.000000  5.000000e+01  \n",
       "rdrinkn_w2      0.000000      1.000000  4.500000e+01  \n",
       "rvgactx_w1      5.000000      5.000000  5.000000e+00  \n",
       "rvgactx_w2      5.000000      5.000000  5.000000e+00  \n",
       "rmdactx_w1      2.000000      4.000000  5.000000e+00  \n",
       "rmdactx_w2      2.000000      4.000000  5.000000e+00  \n",
       "rshlt_w1        3.000000      4.000000  5.000000e+00  \n",
       "rshlt_w2        3.000000      4.000000  5.000000e+00  \n",
       "rhibpe_w1       1.000000      1.000000  1.000000e+00  \n",
       "rhibpe_w2       1.000000      1.000000  1.000000e+00  \n",
       "rdiabe_w1       0.000000      0.000000  1.000000e+00  \n",
       "rdiabe_w2       0.000000      0.000000  1.000000e+00  \n",
       "rcancre_w1      0.000000      0.000000  1.000000e+00  \n",
       "rcancre_w2      0.000000      0.000000  1.000000e+00  \n",
       "rlunge_w1       0.000000      0.000000  1.000000e+00  \n",
       "rlunge_w2       0.000000      0.000000  1.000000e+00  \n",
       "rhearte_w1      0.000000      0.000000  1.000000e+00  \n",
       "rhearte_w2      0.000000      0.000000  1.000000e+00  \n",
       "rstroke_w1      0.000000      0.000000  1.000000e+00  \n",
       "rstroke_w2      0.000000      0.000000  1.000000e+00  "
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hrs.describe().transpose()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [],
   "source": [
    "hrs['country'] = 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "hrs.set_index('hhidpn',inplace=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "hrs = hrs.sort_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>riwstat_w1</th>\n",
       "      <th>riwstat_w2</th>\n",
       "      <th>rage_w1</th>\n",
       "      <th>rage_w2</th>\n",
       "      <th>radla_w1</th>\n",
       "      <th>radla_w2</th>\n",
       "      <th>wgid_w1</th>\n",
       "      <th>wgid_w2</th>\n",
       "      <th>hitot_w1</th>\n",
       "      <th>hitot_w2</th>\n",
       "      <th>...</th>\n",
       "      <th>rdiabe_w2</th>\n",
       "      <th>rcancre_w1</th>\n",
       "      <th>rcancre_w2</th>\n",
       "      <th>rlunge_w1</th>\n",
       "      <th>rlunge_w2</th>\n",
       "      <th>rhearte_w1</th>\n",
       "      <th>rhearte_w2</th>\n",
       "      <th>rstroke_w1</th>\n",
       "      <th>rstroke_w2</th>\n",
       "      <th>country</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>hhidpn</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>000003010</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>68.0</td>\n",
       "      <td>70.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4067.0</td>\n",
       "      <td>4093.0</td>\n",
       "      <td>43736.506385</td>\n",
       "      <td>34076.999401</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>000003020</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>65.0</td>\n",
       "      <td>67.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4132.0</td>\n",
       "      <td>4210.0</td>\n",
       "      <td>43736.506385</td>\n",
       "      <td>34076.999401</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>010001010</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>64.0</td>\n",
       "      <td>66.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>6890.0</td>\n",
       "      <td>7434.0</td>\n",
       "      <td>9298.986526</td>\n",
       "      <td>9329.509552</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>010003030</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>48.0</td>\n",
       "      <td>50.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>10937.843342</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>010004010</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>64.0</td>\n",
       "      <td>66.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5011.0</td>\n",
       "      <td>5217.0</td>\n",
       "      <td>75047.850487</td>\n",
       "      <td>63443.065392</td>\n",
       "      <td>...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 39 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           riwstat_w1  riwstat_w2  rage_w1  rage_w2  radla_w1  radla_w2  \\\n",
       "hhidpn                                                                    \n",
       "000003010           1           1     68.0     70.0       0.0       0.0   \n",
       "000003020           1           1     65.0     67.0       0.0       0.0   \n",
       "010001010           1           1     64.0     66.0       0.0       0.0   \n",
       "010003030           1           1     48.0     50.0       0.0       0.0   \n",
       "010004010           1           1     64.0     66.0       1.0       0.0   \n",
       "\n",
       "           wgid_w1  wgid_w2      hitot_w1      hitot_w2  ...  rdiabe_w2  \\\n",
       "hhidpn                                                   ...              \n",
       "000003010   4067.0   4093.0  43736.506385  34076.999401  ...        0.0   \n",
       "000003020   4132.0   4210.0  43736.506385  34076.999401  ...        0.0   \n",
       "010001010   6890.0   7434.0   9298.986526   9329.509552  ...        0.0   \n",
       "010003030      0.0      0.0      0.000000  10937.843342  ...        0.0   \n",
       "010004010   5011.0   5217.0  75047.850487  63443.065392  ...        0.0   \n",
       "\n",
       "           rcancre_w1  rcancre_w2  rlunge_w1  rlunge_w2  rhearte_w1  \\\n",
       "hhidpn                                                                \n",
       "000003010         0.0         0.0        0.0        0.0         1.0   \n",
       "000003020         1.0         1.0        0.0        0.0         0.0   \n",
       "010001010         0.0         0.0        0.0        0.0         0.0   \n",
       "010003030         0.0         0.0        0.0        0.0         1.0   \n",
       "010004010         1.0         1.0        0.0        0.0         0.0   \n",
       "\n",
       "           rhearte_w2  rstroke_w1  rstroke_w2  country  \n",
       "hhidpn                                                  \n",
       "000003010         1.0         0.0         0.0       10  \n",
       "000003020         0.0         0.0         0.0       10  \n",
       "010001010         0.0         0.0         0.0       10  \n",
       "010003030         1.0         1.0         1.0       10  \n",
       "010004010         0.0         0.0         0.0       10  \n",
       "\n",
       "[5 rows x 39 columns]"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hrs.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [],
   "source": [
    "hrs.to_pickle('../data_sources/hrs/rndhrs_wide_select.pkl')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['riwstat_w1',\n",
       " 'riwstat_w2',\n",
       " 'rage_w1',\n",
       " 'rage_w2',\n",
       " 'radla_w1',\n",
       " 'radla_w2',\n",
       " 'wgid_w1',\n",
       " 'wgid_w2',\n",
       " 'hitot_w1',\n",
       " 'hitot_w2',\n",
       " 'rbmi_w1',\n",
       " 'rbmi_w2',\n",
       " 'rdrink_w1',\n",
       " 'rdrink_w2',\n",
       " 'rsmokev_w1',\n",
       " 'rsmokev_w2',\n",
       " 'rdrinkd_w1',\n",
       " 'rdrinkd_w2',\n",
       " 'rdrinkn_w1',\n",
       " 'rdrinkn_w2',\n",
       " 'rvgactx_w1',\n",
       " 'rvgactx_w2',\n",
       " 'rmdactx_w1',\n",
       " 'rmdactx_w2',\n",
       " 'rshlt_w1',\n",
       " 'rshlt_w2',\n",
       " 'rhibpe_w1',\n",
       " 'rhibpe_w2',\n",
       " 'rdiabe_w1',\n",
       " 'rdiabe_w2',\n",
       " 'rcancre_w1',\n",
       " 'rcancre_w2',\n",
       " 'rlunge_w1',\n",
       " 'rlunge_w2',\n",
       " 'rhearte_w1',\n",
       " 'rhearte_w2',\n",
       " 'rstroke_w1',\n",
       " 'rstroke_w2',\n",
       " 'country']"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hrs.columns.to_list()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "cf2a50979671a58939829e6829efb726aa5da11149213b77bd50351f899d04fb"
  },
  "kernelspec": {
   "display_name": "Python 3.8.5 64-bit ('base': conda)",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.12"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
